package com.bjpowernode.springboot.entity;

import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

@Component
public class Student {
    private Integer id;
    private String name;
    private Integer age;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }


    public static void main(String[] args) {
        Student student = new Student();
        student.setId(1);
        student.setName("zhangsan");
        student.setAge(19);
        Class<? extends Student> clazz = student.getClass();
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            String name = field.getName();
            Class<?> type = field.getType();
            Object o = null;
            try {
                o = field.get(name);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            System.out.println(name + ":" + o);
            System.out.println(type);
        }
    }
}
